import java.util.Random;

public class CalculationSystemV02 {
    // 模块1：生成合法数字（加和≤100，减差≥0）
    public static int[] getValidNums(char op) {
        Random r = new Random();
        int a, b;
        if (op == '+') {
            a = r.nextInt(100) + 1;
            b = r.nextInt(100 - a + 1) + 1;
        } else {
            a = r.nextInt(100) + 1;
            b = r.nextInt(a) + 1;
        }
        return new int[]{a, b};
    }
    // 模块2：生成带答案的算式
    public static String generateFormulaWithAns() {
        char op = (Math.random() > 0.5) ? '+' : '-';
        int[] nums = getValidNums(op);
        int ans = (op == '+') ? nums[0]+nums[1] : nums[0]-nums[1];
        return nums[0] + " " + op + " " + nums[1] + " = " + ans;
    }
    // 模块3：主函数-每行3道题
    public static void main(String[] args) {
        System.out.println("=== 加减法口算系统-v0.2 ===");
        for (int i = 1; i <= 50; i++) {
            System.out.printf("%-22s", generateFormulaWithAns());
            if (i % 3 == 0) System.out.println();
        }
    }
}